<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>Responsables</title>

	
                
<?php 
require_once '../funciones.php'; 
//include ("seguridad.php");
conexion();
$mov='A-LKK317';

   $result=mysql_query("select e.movil as mo, e.fechaevento as fec, e.latitud as lat , e.longitud as lon, e.descripcion as des from seg.eventos as e
where e.movil like '$mov' and month(e.fechaevento)= 3 ");
   
 
              
		$kml='<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
	<name>'.$mov.'.KMZ</name>
	<Style id="point14">
		<IconStyle>
			<scale>1.1</scale>
			<Icon>
				<href>http://maps.google.com/mapfiles/kml/paddle/ylw-circle.png</href>
			</Icon>
			<hotSpot x="32" y="1" xunits="pixels" yunits="pixels"/>
		</IconStyle>
		<ListStyle>
			<ItemIcon>
				<href>http://maps.google.com/mapfiles/kml/paddle/ylw-circle-lv.png</href>
			</ItemIcon>
		</ListStyle>
	</Style>
	<Style id="point13">
		<IconStyle>
			<scale>1.3</scale>
			<Icon>
				<href>http://maps.google.com/mapfiles/kml/paddle/ylw-circle.png</href>
			</Icon>
			<hotSpot x="32" y="1" xunits="pixels" yunits="pixels"/>
		</IconStyle>
		<ListStyle>
			<ItemIcon>
				<href>http://maps.google.com/mapfiles/kml/paddle/ylw-circle-lv.png</href>
			</ItemIcon>
		</ListStyle>
	</Style>
	<StyleMap id="point12">
		<Pair>
			<key>normal</key>
			<styleUrl>#point14</styleUrl>
		</Pair>
		<Pair>
			<key>highlight</key>
			<styleUrl>#point13</styleUrl>
		</Pair>
	</StyleMap>
	<Folder>
		';
                while($row=mysql_fetch_array($result)){
                     
                       $kml=$kml." <name>$mov</name>
		<description>Point Features</description>
		<Placemark>
			<description><![CDATA[".$row['des']."<BR><BR><B>Movil</B> = ".$row['mo']."<BR><BR><B>Fecha </B> = ".$row['fec']."<BR>]]></description>
			<styleUrl>#point12</styleUrl>
			<Point>
                            <coordinates>".$row['lon'].", ".($row['lat']).", 0 </coordinates>
                         </Point>
		</Placemark>
                        ";
                    $i++;
                         
                
                   
                }   
                 $kml=$kml.'	</Folder>
</Document>
</kml>
                    
                ';
                 $texto=$kml;
                  $outputDir = '.';
                 saveFile($texto, $outputDir,$mov,"kml");
function saveFile(&$texto, $outputDir = '.', $mov, $ext)
    {
        if (!$texto) return false;
 
        try
        {
           
            $handle = fopen($outputDir."/$mov-".date("Ymd-His", time()).".$ext",'w+');
            
            $lin = "/$mov-".date("Ymd-His", time()).".$ext";
            echo  '<A href="/seg/kml/'.$lin.'">Descargar '.$lin.'</A>';
            fwrite($handle, $texto);
            fclose($handle);
        }
        catch (Exception $e)
        {
            var_dump($e->getMessage());
            return false;
        }
 
        return true;
    }       
                 
                 
                 ?> 

	</head>
	<body>




	</body>
</html>

